package edu.zut.cs.javaee.dream.customer.web.spring.controller;

import com.alibaba.fastjson.JSON;
import edu.zut.cs.javaee.dream.admin.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.zut.cs.javaee.dream.base.web.spring.controller.GenericController;
import edu.zut.cs.javaee.dream.customer.domain.Customer;
import edu.zut.cs.javaee.dream.customer.service.CustomerManager;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;

@Controller
@RequestMapping("/customer")
public class CustomerController extends GenericController<Customer, Long, CustomerManager> {

    CustomerManager customerManager;

    @Autowired
    public void setCustomerManager(CustomerManager customerManager) {
        this.customerManager = customerManager;
        this.manager = this.customerManager;
    }

    @ResponseBody
    @RequestMapping("/findbylist/{fullname}")
    public String fingbyName(@PathVariable("fullname") String fullname){
        List<Customer> list = customerManager.findByFullname(fullname);
        HashMap<String,Object> map = new HashMap<>();
        map.put("number",list.size());
        map.put("userList",list);
        String res = JSON.toJSONString(map);
        return res;
    }

}
